package com.example.jdbcdemo.controller;

import com.alibaba.fastjson.JSON;
import com.example.jdbcdemo.service.StatsCustServiceInterface;
import com.example.jdbcdemo.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stats")
public class StatsCustSalesController {

    @Autowired
    StatsCustServiceInterface statsCustServiceInterface;

    @PostMapping("/customer")
    public JsonUtil StatsCustSales(){
        List<Map<String,Object>> list=statsCustServiceInterface.StatsCustomerSales();
        if (list.isEmpty()||list==null)
        {
            return new JsonUtil(400,"未找到相关记录","[]");
        }
        return new JsonUtil(0,"统计成功", JSON.toJSONString(list));
    }

    @PostMapping("/onecustomer")
    public JsonUtil OneCustSale(@RequestBody Map<String,Object> map){
        List<Map<String,Object>> list=statsCustServiceInterface.queryCollectOrderListByCustId((Integer) map.get("customerId"));
        if (list.isEmpty()||list==null)
        {
            return new JsonUtil(400,"未找到相关记录","[]");
        }
        return new JsonUtil(0,"统计成功", JSON.toJSONString(list));
    }
}
